package metalink.admin;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;
import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;


public class PopulateStaffList extends ActionSupport{
ArrayList<CollegeStaffVo> staff_list=new ArrayList<CollegeStaffVo>();
ArrayList<CollegeStaffVo> staff_edit_list=new ArrayList<CollegeStaffVo>();
private int result;


int staff_id;
String staff_name;
String designation;
String joining_date;
String phone_number;
String address_line;
String city;
String state;
String country;
int staff_type;
String role;
String roll_number;
int acc_no;
String email_id;
String edit="";
String update="";
String delete="";
String insert="";
String add="";

//------------ Pagination --------------//
private int page;
private String morepages;
private Vector noofpages=new Vector();
private int nextpage;
private int currentpage;
private String hasprevpage;
private int prevpage;
private int items;
//private Vector pagelist=new Vector();
private ArrayList<CollegeStaffVo> pagelist;

public ArrayList<CollegeStaffVo> getStaff_list() {
	return staff_list;
}
public void setStaff_list(ArrayList<CollegeStaffVo> staff_list) {
	this.staff_list = staff_list;
}

public String execute(){
	
	PopulateStaffListMo mo= new PopulateStaffListMo();
	if(edit.contentEquals("yes")){
		pagelist = new ArrayList<CollegeStaffVo>();
		staff_edit_list=mo.singleStaffInfo(staff_id);
		result = staff_edit_list.size();
		
		
		//---------- Pagination ------------------//
		
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=staff_edit_list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(staff_edit_list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
	}else if(update.contentEquals("yes")){
		pagelist = new ArrayList<CollegeStaffVo>();
		mo.updateStaff(staff_id, staff_name, designation, joining_date, phone_number, address_line, city, state, country, staff_type, role,edit);
		staff_list=mo.retrievestaff();
		result = staff_list.size();
		
		
		//---------- Pagination ------------------//
		
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=staff_list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(staff_list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
	}else if(delete.contentEquals("yes")){
		pagelist = new ArrayList<CollegeStaffVo>();
		mo.deleteStaff(staff_id,delete);
		staff_list=mo.retrievestaff();
		result = staff_list.size();
		
		
		//---------- Pagination ------------------//
		
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=staff_list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(staff_list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
	}else if(insert.contentEquals("yes")){
		pagelist = new ArrayList<CollegeStaffVo>();
		mo.addstaff(staff_id, staff_name, designation, joining_date, phone_number, address_line, city, state, country,email_id, staff_type, role, roll_number, acc_no,insert);
		staff_list=mo.retrievestaff();
result = staff_list.size();
		
		
		//---------- Pagination ------------------//
		
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=staff_list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(staff_list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
	}else if(add.contentEquals("yes")){
		return SUCCESS;
	}
	else{
		pagelist = new ArrayList<CollegeStaffVo>();
		staff_list=mo.retrievestaff();
result = staff_list.size();
		
		
		//---------- Pagination ------------------//
		
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=staff_list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(staff_list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
	}
	return SUCCESS;
	
}
/*
public String execute(){
	pagelist = new ArrayList<CollegeStaffVo>();
	staff_list=new PopulateStaffListMo().retrievestaff();
	result = staff_list.size();
	
	
	//---------- Pagination ------------------//
	
		int p=getPage();
	    if(p==0)
	    {
	        setHasprevpage("false");
	    }
	    else
	    {
	        setHasprevpage("true");
	        setPrevpage(p-1);
	    }

	    setCurrentpage(p);

	    int count;
	    count=0;

	    int size=staff_list.size();
	    setItems(size);
	    int pagesinlist=size/15;
	    while(count<=pagesinlist)
	    {
	        noofpages.add(count);
	        count++;
	    }
	    count=0;
	    while(count<15)
	    {

	        if(size>=(p*15)+count+1)
	        {
	            System.out.println(p);
	            pagelist.add(staff_list.get((p*15)+count));
	            System.out.println((p*15)+count);
	            System.out.println("size"+pagelist.size());
	            count++;
	            setMorepages("true");
	            setNextpage(p+1);

	        }
	        else
	        {
	            setMorepages("false");
	            break;
	        }
	    }
		
	
	
	
	return SUCCESS;
	
}
*/
public int getResult() {
	return result;
}
public void setResult(int result) {
	this.result = result;
}
public int getPage() {
	return page;
}
public void setPage(int page) {
	this.page = page;
}
public String getMorepages() {
	return morepages;
}
public void setMorepages(String morepages) {
	this.morepages = morepages;
}
public Vector getNoofpages() {
	return noofpages;
}
public void setNoofpages(Vector noofpages) {
	this.noofpages = noofpages;
}
public int getNextpage() {
	return nextpage;
}
public void setNextpage(int nextpage) {
	this.nextpage = nextpage;
}
public int getCurrentpage() {
	return currentpage;
}
public void setCurrentpage(int currentpage) {
	this.currentpage = currentpage;
}
public String getHasprevpage() {
	return hasprevpage;
}
public void setHasprevpage(String hasprevpage) {
	this.hasprevpage = hasprevpage;
}
public int getPrevpage() {
	return prevpage;
}
public void setPrevpage(int prevpage) {
	this.prevpage = prevpage;
}
public int getItems() {
	return items;
}
public void setItems(int items) {
	this.items = items;
}
public ArrayList<CollegeStaffVo> getPagelist() {
	return pagelist;
}
public void setPagelist(ArrayList<CollegeStaffVo> pagelist) {
	this.pagelist = pagelist;
}
public ArrayList<CollegeStaffVo> getStaff_edit_list() {
	return staff_edit_list;
}
public void setStaff_edit_list(ArrayList<CollegeStaffVo> staff_edit_list) {
	this.staff_edit_list = staff_edit_list;
}
public int getStaff_id() {
	return staff_id;
}
public void setStaff_id(int staff_id) {
	this.staff_id = staff_id;
}
public String getStaff_name() {
	return staff_name;
}
public void setStaff_name(String staff_name) {
	this.staff_name = staff_name;
}
public String getDesignation() {
	return designation;
}
public void setDesignation(String designation) {
	this.designation = designation;
}
public String getJoining_date() {
	return joining_date;
}
public void setJoining_date(String joining_date) {
	this.joining_date = joining_date;
}
public String getPhone_number() {
	return phone_number;
}
public void setPhone_number(String phone_number) {
	this.phone_number = phone_number;
}
public String getAddress_line() {
	return address_line;
}
public void setAddress_line(String address_line) {
	this.address_line = address_line;
}
public String getCity() {
	return city;
}
public void setCity(String city) {
	this.city = city;
}
public String getState() {
	return state;
}
public void setState(String state) {
	this.state = state;
}
public String getCountry() {
	return country;
}
public void setCountry(String country) {
	this.country = country;
}
public int getStaff_type() {
	return staff_type;
}
public void setStaff_type(int staff_type) {
	this.staff_type = staff_type;
}
public String getRole() {
	return role;
}
public void setRole(String role) {
	this.role = role;
}
public String getRoll_number() {
	return roll_number;
}
public void setRoll_number(String roll_number) {
	this.roll_number = roll_number;
}
public int getAcc_no() {
	return acc_no;
}
public void setAcc_no(int acc_no) {
	this.acc_no = acc_no;
}
public String getEmail_id() {
	return email_id;
}
public void setEmail_id(String email_id) {
	this.email_id = email_id;
}
public String getEdit() {
	return edit;
}
public void setEdit(String edit) {
	this.edit = edit;
}
public String getUpdate() {
	return update;
}
public void setUpdate(String update) {
	this.update = update;
}
public String getDelete() {
	return delete;
}
public void setDelete(String delete) {
	this.delete = delete;
}
public String getInsert() {
	return insert;
}
public void setInsert(String insert) {
	this.insert = insert;
}
public String getAdd() {
	return add;
}
public void setAdd(String add) {
	this.add = add;
}
}
